<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:HAOest.WPF.Buttons">

    <ImageBrush x:Key="MouseOverImage" ImageSource="{Binding MouseOverImage, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Win8Button}}}" Stretch="Uniform"/>
    <SolidColorBrush x:Key="MouseOverColor" Color="{Binding MouseOverColor, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Win8Button}}}" />

    <Style TargetType="{x:Type local:Win8Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:Win8Button}">
                    <Grid x:Name="grid"
                          Background="{TemplateBinding Background}">
                        <Border x:Name="border" 
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                Background="{TemplateBinding Background}" />
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" TargetName="grid" Value="{StaticResource MouseOverImage}" />
                            <Setter Property="Background" TargetName="border" Value="{StaticResource MouseOverColor}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="CloseButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Template" Value="{DynamicResource CloseButtonControlTemplate}"/>
    </Style>
    <ControlTemplate x:Key="CloseButtonControlTemplate" TargetType="{x:Type Button}">
        <Grid>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="MouseOver"/>
                    <VisualState x:Name="Pressed"/>
                    <VisualState x:Name="Disabled"/>
                </VisualStateGroup>
                <VisualStateGroup x:Name="FocusStates">
                    <VisualState x:Name="Focused"/>
                </VisualStateGroup>
                <VisualStateGroup x:Name="ValidationStates">
                    <VisualState x:Name="InvalidFocused"/>
                    <VisualState x:Name="InvalidUnfocused"/>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border x:Name="CloseButtonBorder" BorderBrush="{DynamicResource CloseButtonBorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{DynamicResource CloseButtonBackground}" />
            <Border x:Name="CloseButtonInnerBorder" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" SnapsToDevicePixels="True" Background="#00000000">
                <Path x:Name="CloseButtonPath" Data="M0,0 L2.1779997,0 4.9874997,2.9132754 7.7969999,0 9.9750004,0 6.0764999,4.0425005 9.9749994,8.085 7.7969995,8.085 4.9874997,5.1717248 2.178,8.085 0,8.085 3.8985,4.0425 z" Fill="#B2FFFFFF" Height="8.08500003814697" Stretch="Fill" Width="9.975" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0"/>
            </Border>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsFocused" Value="True"/>
            <Trigger Property="IsDefaulted" Value="True"/>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="CloseButtonBorder" Property="Background" Value="{DynamicResource ResourceKey=CloseButtonMouseOverBackground}" />
                <Setter TargetName="CloseButtonBorder" Property="BorderBrush" Value="{DynamicResource CloseButtonMouseOverBorderBrush}" />
                <Setter TargetName="CloseButtonPath" Property="Fill" Value="White"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True"/>
            <Trigger Property="IsEnabled" Value="False"/>
        </ControlTemplate.Triggers>
    </ControlTemplate>


</ResourceDictionary>